home *** CD-ROM | disk | FTP | other *** search
/ Collection of Tools & Utilities / Collection of Tools and Utilities.iso / bbsutil / hsrc_117.zip / KILLJUNK.C < prev    next >
Text File  |  1990-11-12  |  7KB  |  231 lines

  1. #include "msgg.h"
  2. #include "twindow.h"
  3. #include "keys.h"
  4. #include "headedit.h"
  5.  
  6.  
  7.  
  8. void pascal killjunk (void) {
  9.  
  10.     static char from[36]="JACK DECKER";
  11.     static char to[36]="";
  12.     static char subj[64]="POLITICS AND RELIGION";
  13.     static char orit[2]="-";
  14.     char listtouse[80]="";
  15.     char area[5]="0";
  16.     word temparea;
  17.     word tempno;
  18.     word tempmess;
  19.     int  returncode;
  20.     word register x;
  21.     char testfrom[36];
  22.     char testto[64];
  23.     char testsubj[64];
  24.     char frommatch;
  25.     char tomatch;
  26.     char subjmatch;
  27.     int  handle=-1;
  28.     char input[133];
  29.     char *p;
  30.     WINDOW *wnd;
  31.     WINDOW *wndd=NULL;
  32.     FIELD *fld;
  33.  
  34.  
  35.     wnd=establish_window(1,8,12,79);
  36.     set_border(wnd,3);
  37.     set_title(wnd," Kill Junk Msgs ");
  38.     set_colors(wnd,BORDER,7,0,0);
  39.     display_window(wnd);
  40.     wcursor(wnd,0,0);
  41.     wprintfraw(wnd," F10 to kill or ESC to abort");
  42.     temparea=areano;
  43.     tempno=nomess;
  44.     tempmess=messno;
  45. Again:
  46.     wprompt(wnd,3,2,"From:");
  47.     wprompt(wnd,3,3,"To:");
  48.     wprompt(wnd,3,4,"Subj:");
  49.     wprompt(wnd,3,5,"Area #(0=all):");
  50.     wprompt(wnd,3,6,"Match any: [ ]");
  51.     wprompt(wnd,3,7,"List to use instead:");
  52.  
  53.     fld=establish_field(wnd,9,2,msk35,from,'A');
  54.     field_window(fld,"killfrom  ",40,5);
  55.     fld=establish_field(wnd,9,3,msk35,to,'A');
  56.     field_window(fld,"killto    ",40,6);
  57.     fld=establish_field(wnd,9,4,msk63,subj,'A');
  58.     field_window(fld,"killsubj  ",40,7);
  59.     fld=establish_field(wnd,18,5,msk4,area,'N');
  60.     field_window(fld,"killarea  ",40,8);
  61.     fld=establish_field(wnd,15,6,msk1,orit,'O');
  62.     field_window(fld,"matchany  ",40,8);
  63.     fld=establish_field(wnd,1,8,msk78,listtouse,'A');
  64.     field_window(fld,"listtouse ",40,5);
  65.     prep_template(wnd);
  66. AskOver:
  67.     returncode=data_entry(wnd);
  68.     if (returncode==ESC) {
  69.         delete_window(wnd);
  70.         clear_message();
  71.         return;
  72.     }
  73.     if (returncode!=F10) goto AskOver;
  74. Quit:
  75.     delete_window(wnd);
  76.     lstrip(listtouse);
  77.     rstrip(listtouse);
  78.     if(*listtouse) {
  79.         handle=_open(listtouse,O_RDONLY | O_BINARY | O_DENYNONE);
  80.         if(handle==-1) {
  81. ErrorHere:
  82.             error_message(" Can't open Junk list file ");
  83.             pause();
  84.             return;
  85.         }
  86.         if(eof(handle)) goto ErrorHere;
  87.     }
  88. ReLoop:
  89.     if(*listtouse) {
  90.         if(eof(handle)) {
  91.             *listtouse=0;
  92.             goto SkipNext;
  93.         }
  94.         if(!fgetsx(input,133,handle)) {
  95.             *listtouse=0;
  96.             goto SkipNext;
  97.         }
  98.         stripcr(input);
  99.         p=strtok(input,"\01");
  100.         strncpy(from,p,36);
  101.         from[35]=0;
  102.         p=strtok(0,"\01");
  103.         if(p) {
  104.             strcpy(to,p);
  105.             to[35]=0;
  106.             p=strtok(0,"\01");
  107.             if(p) {
  108.                 strcpy(subj,p);
  109.                 subj[63]=0;
  110.                 p=strtok(0,"\01");
  111.                 if(p) {
  112.                     strncpy(area,p,5);
  113.                     area[4]=0;
  114.                     p=strtok(0,"\01");
  115.                     if(p) {
  116.                         *orit=*p;
  117.                     }
  118.                 }
  119.             }
  120.         }
  121.     }
  122.     rstrip(from);
  123.     rstrip(to);
  124.     rstrip(subj);
  125.     if(!strnicmp(subj,"RE:",3)) {
  126.         strcpy(testsubj,&subj[3]);
  127.         strcpy(subj,testsubj);
  128.         lstrip(subj);
  129.     }
  130.     if (!*from && !*to && !*subj) {
  131.         if(!*listtouse) return;
  132.         else goto ReLoop;
  133.     }
  134.     if (atol(area)<0 || atol(area)>4095) {
  135.         error_message(" Invalid area ");
  136.         pause();
  137.         if(*listtouse) goto ReLoop;
  138.         else return;
  139.     }
  140.     if(!wndd) {
  141.         wndd=establish_window(1,4,18,79);
  142.         set_border(wndd,1);
  143.         set_title(wndd," Junk Killing Status (ESC Aborts) ");
  144.         set_colors(wndd,BORDER,7,0,0);
  145.         display_window(wndd);
  146.         wcursor(wndd,0,0);
  147.     }
  148.     if (atol(area)) {
  149.         areano=(word)atol(area);
  150.         find_area();
  151.         nomess=check_area(areano);
  152.         if(!nomess)goto SkipNext;
  153.         goto SkipFor;
  154.     }
  155.  
  156.     for (x=0;x<(maxareas+1);x++) {
  157.          areano=marea[x].number;
  158.          currarea=(struct _marea far *)&marea[x];
  159.          nomess=check_area(areano);
  160.          if(!nomess) continue;
  161. SkipFor:
  162.          clear_message();
  163.          wprintf(wndd,"\n\n Scanning area #%u (%1.24s) 1-%u",areano,currarea->name,nomess);
  164.          for (messno=1;messno<(nomess+1);messno++) {
  165.             if (kbhit()) if (get_char()==ESC) {
  166.                 *listtouse=0;
  167.                 goto SkipNext;
  168.             }
  169.             get_mess(0);
  170.  
  171.             if (*from) {
  172.                 strcpy(testfrom,msg.from);
  173.                 if (!stricmp(testfrom,from)) frommatch=1;
  174.                 else frommatch=0;
  175.             }
  176.             else if(*orit=='X') frommatch=0;
  177.             else frommatch=1;
  178.             if (*to) {
  179.                 strcpy(testto,msg.to);
  180.                 if (!stricmp(testto,to)) tomatch=1;
  181.                 else tomatch=0;
  182.             }
  183.             else if(*orit=='X') tomatch=0;
  184.             else tomatch=1;
  185.             if(*subj) {
  186.                 strcpy(testsubj,msg.subj);
  187.                 if(!strnicmp(testsubj,"RE:",3)) {
  188.                     strcpy(testto,&testsubj[3]);
  189.                     strcpy(testsubj,testto);
  190.                     lstrip(testsubj);
  191.                     if(!*testsubj) {
  192.                         subjmatch=1;
  193.                         goto BreakOut;
  194.                     }
  195.                 }
  196.                 if(!stricmp(testsubj,subj)) subjmatch=1;
  197.                 else subjmatch=0;
  198.             }
  199.             else if (*orit=='X') subjmatch=0;
  200.             else subjmatch=1;
  201. BreakOut:
  202.  
  203.             if((*orit=='X' && (frommatch || tomatch || subjmatch)) || (frommatch && tomatch && subjmatch)) {
  204.                     reverse_video(wndd);
  205.                     wputchar(wndd,'\n');
  206.                     wprintfraw(wndd,"%05u Subj: %-64s",messno,msg.subj);
  207.                     normal_video(wndd);
  208.                     wputchar(wndd,'\n');
  209.                     wprintfraw(wndd,"Fm: %-32s To: %s",msg.from,msg.to);
  210.                     wputchar(wndd,'\n');
  211.                     wprintf(wndd,"%s %s",msg.date,quick_attr());
  212.                     msg.m_attr = (msg.m_attr | MSGDELETED);
  213.                     put_mess();
  214.             }
  215.          }
  216.          if (atol(area)) goto SkipNext;
  217.     }
  218. SkipNext:
  219.     clear_message();
  220.     if(*listtouse) goto ReLoop;
  221.     if(wndd)delete_window(wndd);
  222.     messno=tempmess;
  223.     nomess=tempno;
  224.     areano=temparea;
  225.     find_area();
  226.     get_mess(0);
  227.     if(handle!=-1) _close(handle);
  228.     return;
  229. }
  230.  
  231.